﻿/*
 * @(#)Celebrities gadget 24/01/07
 * Copyright 2007  Hemakumar M. All rights reserved.
 */
var url_santabanta_bollywood = "http://www.santabanta.com/rss/wallpaper.asp";
var url_santabanta_global = url_santabanta_bollywood + "?parentid=8";
var url_open = "http://www.santabanta.com/";
var slideshow_interval = 30; //secs
var title ="";
var link = "";
var url = ""; 
var global_checked = false;
var isPlaying = true;

function view_onOpen()
{
  pluginHelper.onAddCustomMenuItems = onAddCustomMenuItems;
  RequestFeed();
  utils.setInterval(RequestFeed, 1000 * slideshow_interval);
}

function onAddCustomMenuItems(menu) {
  menu.AddItem("Include Hollywood", global_checked ? gddMenuItemFlagChecked : 0, IncludeHollywood);
}


function IncludeHollywood() {
 global_checked = !global_checked;
}

function RequestFeed()  {
  if(isPlaying)
  {  
    var http  = new XMLHttpRequest();
    http.open("GET", global_checked? url_santabanta_global : url_santabanta_bollywood, false);
    http.onreadystatechange = function() {  
		if(http.readyState==4) 
			if(http.status==200) { 
			   ParseFeed(http.responseText);
			}
		};
   
    http.setRequestHeader("Cache-Control","no-cache");
    http.send();
  }
}

function ParseFeed(feed) {
  var doc = new DOMDocument();
  doc.loadXML(feed);
  var image = doc.getElementsByTagName("image");
  if(image.length>0) {
    for (var node = image[0].firstChild; node != null; node = node.nextSibling) {
      if(node.nodeName=="title") title = node.firstChild.nodeValue;
      if(node.nodeName=="link") link = node.firstChild.nodeValue;
      if(node.nodeName=="url") url = node.firstChild.nodeValue;
    }
  }
  FetchImage(url);
}


function FetchImage(url)
{
var http = new XMLHttpRequest(); 
http.onreadystatechange = LoadImg; 
http.open("GET", url, "true"); 
http.setRequestHeader("Cache-Control","no-cache");
http.send(); 
   function LoadImg()
   {  
      if(http.readyState == 4) 
      { 
            var imgSrc = http.responseStream; 
            img_celebrity.src = imgSrc;
            //img_celebrity.tooltip = title;
	    url_open = link;
      }
   }
}

function OpenUrl() {
   //debug.trace("In Open Url");
   var run = new ActiveXObject("Shell.Application"); 
   run.ShellExecute(url_open); 
}


function view_onsizing() {
    var current = event;
    var ratio = Math.min(current.width / img_celebrity.srcWidth,
                         current.height / img_celebrity.srcHeight);

    img_celebrity.width = img_celebrity.srcWidth * ratio;
    img_celebrity.height = img_celebrity.srcHeight * ratio;
}
function imgOnMouseOver() {
   lbl_title.y = img_celebrity.height - 20;
   lbl_title.visible = true;
   lbl_title.innerText = title;
   
}

function imgOnMouseOut() {
   lbl_title.visible = false;
}

function OnClickPlay() {
  if(!isPlaying)
   {
     btn_play.image = "btn_pause.gif";
     btn_play.overImage = "btn_pause_o.gif";
     btn_play.downImage = "btn_pause.gif";
   }else {
     btn_play.image = "btn_play.gif";
     btn_play.overImage = "btn_play_o.gif";
     btn_play.downImage = "btn_play.gif";
   }
   isPlaying = !isPlaying;  
}